set more off
clear


cap cd "Set Directory"
log using replication2, replace
use Schuler_GenderAndClientelism_Replication3 /* This dataset contains the 2022 PAPI survey; It has dropped a subset of respondents who were given a treatment that varied sexual orientation in addition to gender; it also drops a subset of respondents who were asked to evaluate village leader candidates instead of national assembly delegates */

save temp1, replace
* Client Group variables are the three treatments: 1 is the control (no prime), 2 prime honesty, 3 primes clientelism
gen client_group=1
replace client_group=2 if  d101e_random >.333 & d101e_random<.666
replace client_group=3 if  d101e_random>.666

* The following generates the randomized attributes for candidate 1
gen age29 = .
replace age29 = 1 if d102_age1==3
replace age29 = 0 if d102_age1==1
replace age29 = 0 if d102_age1==4
replace age29 = 0 if d102_age1==2
gen age39 = .
replace age39 = 1 if d102_age1==1
replace age39 = 0 if d102_age1==3
replace age39 = 0 if d102_age1==4
replace age39 = 0 if d102_age1==2
gen age49 = .
replace age49 = 1 if d102_age1==4
replace age49 = 0 if d102_age1==1
replace age49 = 0 if d102_age1==2
replace age49 = 0 if d102_age1==3
gen age59 = .
replace age59 = 1 if d102_age1==2
replace age59 = 0 if d102_age1==1
replace age59 = 0 if d102_age1==3
replace age59 = 0 if d102_age1==4

gen sex = d102_sex1
gen female = .
replace female = 1 if d102_sex1==2
replace female = 0 if d102_sex1==1
replace female = 0 if d102_sex1==3
replace female = 0 if d102_sex1==4
gen male_del = .
replace male_del = 1 if d102_sex1==1
replace male_del = 0 if d102_sex1==2
replace male_del = 0 if d102_sex1==3
replace male_del = 0 if d102_sex1==4
gen gay_male = .
replace gay_male = 0 if d102_sex1==1
replace gay_male = 0 if d102_sex1==2
replace gay_male = 1 if d102_sex1==3
replace gay_male = 0 if d102_sex1==4
gen gay_female = .
replace gay_female = 0 if d102_sex1==1
replace gay_female = 0 if d102_sex1==2
replace gay_female = 0 if d102_sex1==3
replace gay_female = 1 if d102_sex1==4

gen high_school= .
replace high_school=1 if d102_edu1==1
replace high_school=0 if d102_edu1==2
replace high_school=0 if d102_edu1==3
replace high_school=0 if d102_edu1==4
gen bachelors=.
replace bachelors=1 if d102_edu1==2
replace bachelors=0 if d102_edu1==1
replace bachelors=0 if d102_edu1==3
replace bachelors=0 if d102_edu1==4
gen masters=.
replace masters=1 if d102_edu1==3
replace masters=0 if d102_edu1==1
replace masters=0 if d102_edu1==2
replace masters=0 if d102_edu1==4
gen doctorate=0
replace doctorate=1 if d102_edu1==4
replace doctorate=0 if d102_edu1==1
replace doctorate=0 if d102_edu1==2
replace doctorate=0 if d102_edu1==3


gen party=.
replace party=1 if d102_party1==1
replace party=0 if d102_party1==2
gen non_party = .
replace non_party=1 if d102_party1==2
replace non_party=0 if d102_party1==1


gen ben_citizen = .
replace ben_citizen=1 if d102_ben1==1
replace ben_citizen=0 if d102_ben1==2
replace ben_citizen=0 if d102_ben1==3
replace ben_citizen=0 if d102_ben1==4
replace ben_citizen=0 if d102_ben1==5
gen ben_biz = .
replace ben_biz=1 if d102_ben1==2
replace ben_biz=0 if d102_ben1==1
replace ben_biz=0 if d102_ben1==3
replace ben_biz=0 if d102_ben1==4
replace ben_biz=0 if d102_ben1==5
gen ben_leaders = .
replace ben_leaders=1 if d102_ben1==3
replace ben_leaders=0 if d102_ben1==1
replace ben_leaders=0 if d102_ben1==2
replace ben_leaders=0 if d102_ben1==4
replace ben_leaders=0 if d102_ben1==5
gen ben_social = .
replace ben_social=1 if d102_ben1==4
replace ben_social=0 if d102_ben1==1
replace ben_social=0 if d102_ben1==2
replace ben_social=0 if d102_ben1==3
replace ben_social=0 if d102_ben1==5
gen ben_community = .
replace ben_community=1 if d102_ben1==5
replace ben_community=0 if d102_ben1==1
replace ben_community=0 if d102_ben1==2
replace ben_community=0 if d102_ben1==3
replace ben_community=0 if d102_ben1==4


gen inclan = .
replace inclan = 0 if d102_rel1==1
replace inclan = 1 if d102_rel1==2

gen outclan = .
replace outclan = 0 if d102_rel1==2
replace outclan = 1 if d102_rel1==1

gen vote = .
replace vote = 0 if d102a==2
replace vote = 1 if d102a==1
replace vote = 0 if d102b==2
replace vote = 1 if d102b==1
replace vote = 0 if d102c==2
replace vote = 1 if d102c==1
replace vote = 0 if d102d==2
replace vote = 1 if d102d==1


save NA_formA.dta, replace

use temp1, replace

gen client_group=1
replace client_group=2 if  d101e_random >.333 & d101e_random<.666
replace client_group=3 if  d101e_random>.666

* The following generates the randomized attributes for candidate 2
gen age29 = .
replace age29 = 1 if d102_age2==3
replace age29 = 0 if d102_age2==1
replace age29 = 0 if d102_age2==4
replace age29 = 0 if d102_age2==2
gen age39 = .
replace age39 = 1 if d102_age2==1
replace age39 = 0 if d102_age2==3
replace age39 = 0 if d102_age2==4
replace age39 = 0 if d102_age2==2
gen age49 = .
replace age49 = 1 if d102_age2==4
replace age49 = 0 if d102_age2==1
replace age49 = 0 if d102_age2==2
replace age49 = 0 if d102_age2==3
gen age59 = .
replace age59 = 1 if d102_age2==2
replace age59 = 0 if d102_age2==1
replace age59 = 0 if d102_age2==3
replace age59 = 0 if d102_age2==4

gen sex = d102_sex2
gen female = .
replace female = 1 if d102_sex2==2
replace female = 0 if d102_sex2==1
replace female = 0 if d102_sex2==3
replace female = 0 if d102_sex2==4
gen male_del = .
replace male_del = 1 if d102_sex2==1
replace male_del = 0 if d102_sex2==2
replace male_del = 0 if d102_sex2==3
replace male_del = 0 if d102_sex2==4
gen gay_male = .
replace gay_male = 0 if d102_sex2==1
replace gay_male = 0 if d102_sex2==2
replace gay_male = 1 if d102_sex2==3
replace gay_male = 0 if d102_sex1==4
gen gay_female = .
replace gay_female = 0 if d102_sex2==1
replace gay_female = 0 if d102_sex2==2
replace gay_female = 0 if d102_sex2==3
replace gay_female = 1 if d102_sex2==4



gen high_school= .
replace high_school=1 if d102_edu2==1
replace high_school=0 if d102_edu2==2
replace high_school=0 if d102_edu2==3
replace high_school=0 if d102_edu2==4
gen bachelors=.
replace bachelors=1 if d102_edu2==2
replace bachelors=0 if d102_edu2==1
replace bachelors=0 if d102_edu2==3
replace bachelors=0 if d102_edu2==4
gen masters=.
replace masters=1 if d102_edu2==3
replace masters=0 if d102_edu2==1
replace masters=0 if d102_edu2==2
replace masters=0 if d102_edu2==4
gen doctorate=0
replace doctorate=1 if d102_edu2==4
replace doctorate=0 if d102_edu2==1
replace doctorate=0 if d102_edu2==2
replace doctorate=0 if d102_edu2==3


gen party=.
replace party=1 if d102_party2==1
replace party=0 if d102_party2==2
gen non_party = .
replace non_party=1 if d102_party2==2
replace non_party=0 if d102_party2==1


gen ben_citizen = .
replace ben_citizen=1 if d102_ben2==1
replace ben_citizen=0 if d102_ben2==2
replace ben_citizen=0 if d102_ben2==3
replace ben_citizen=0 if d102_ben2==4
replace ben_citizen=0 if d102_ben2==5
gen ben_biz = .
replace ben_biz=1 if d102_ben2==2
replace ben_biz=0 if d102_ben2==1
replace ben_biz=0 if d102_ben2==3
replace ben_biz=0 if d102_ben2==4
replace ben_biz=0 if d102_ben2==5
gen ben_leaders = .
replace ben_leaders=1 if d102_ben2==3
replace ben_leaders=0 if d102_ben2==1
replace ben_leaders=0 if d102_ben2==2
replace ben_leaders=0 if d102_ben2==4
replace ben_leaders=0 if d102_ben2==5
gen ben_social = .
replace ben_social=1 if d102_ben2==4
replace ben_social=0 if d102_ben2==1
replace ben_social=0 if d102_ben2==2
replace ben_social=0 if d102_ben2==3
replace ben_social=0 if d102_ben2==5
gen ben_community = .
replace ben_community=1 if d102_ben2==5
replace ben_community=0 if d102_ben2==1
replace ben_community=0 if d102_ben2==2
replace ben_community=0 if d102_ben2==3
replace ben_community=0 if d102_ben2==4


gen inclan = .
replace inclan = 0 if d102_rel2==1
replace inclan = 1 if d102_rel2==2

gen outclan = .
replace outclan = 0 if d102_rel2==2
replace outclan = 1 if d102_rel2==1

gen vote = .
replace vote = 1 if d102a==2
replace vote = 0 if d102a==1
replace vote = 1 if d102b==2
replace vote = 0 if d102b==1
replace vote = 1 if d102c==2
replace vote = 0 if d102c==1
replace vote = 1 if d102d==2
replace vote = 0 if d102d==1

save NA_formB.dta, replace

append using NA_formA.dta

gen client_important = .
replace client_important = 0 if d101e3==1
replace client_important = 1 if d101e3==2
replace client_important = 1 if d101e3==3

replace non_party=0 if non_party==.


xtile income_pc = d611ai if d611ai!=. & d611ai<60, n(4)
label var income_pc "Income Percentile"

xtile education_pc = a006 if a006!=. & a006<100, n(4)
label var education_pc "Education Percentile"


gen male = 0 
replace male =1 if a001==1
gen woman = 0 
replace woman =1 if a001==2
tab male
gen age = a002
mean age


gen women_union = 0
replace women_union =1 if a016_opt17==1
gen youth_union = 0
replace youth_union = 1 if a016_opt18 ==1
gen farmer_union = 0
replace farmer_union = 1 if a016_opt9 ==1
gen labor_union = 0
replace labor_union = 1 if a016_opt8 ==1
gen mass_org=0
replace mass_org = 1 if women_union==1
replace mass_org = 1 if farmer_union==1
replace mass_org = 1 if youth_union==1
replace mass_org = 1 if labor_union==1
gen party_mem = 0
replace party_mem = 1 if a016_opt1==1
gen social_ins=0
replace social_ins=1 if d602aa==1
gen kinh = 1
replace kinh = 0 if a005!=1

label define female  1  "Woman Candidate" 0 "Man Candidate" 
label values female female


reg vote  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan i.female  if  client_group==1, cluster(id)
outreg2 using main_results_11_11, e(all) replace
margins, dydx(  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan  i.female )
marginsplot,  horizontal plotopts(connect(none)) xline(0, lpattern(dash) lwidth(thick) lcolor(maroon)) title("")   recastci(rcap) ciopts(lcolor(navy) lwidth(thick) mcolor(navy) msymbol(i) msize(tiny)) ylabel( 1 "Focus - Community" 2 "Focus - Business" 3 "Focus - Leader" 4 "Age - 59"  5 "Age - 49" 6 "Age - 39"  7 "Education - Doctor" 8 "Education - Masters" 9 "Education - Bachelors" 10 "Non-Party Member" 11 "In Family Network" 12 "Woman", labsize(vsmall))  xtitle("AMCE on Vote Choice", size(small) margin(medium))  xlabel(-.25(.05).25)  ytitle("") title("Control Group")
graph save control_11_11, replace

reg vote  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan i.female  if  client_group==2, cluster(id)
outreg2 using main_results_11_11, e(all) 
margins, dydx(  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan  i.female )
marginsplot,  horizontal plotopts(connect(none)) xline(0, lpattern(dash) lwidth(thick) lcolor(maroon)) title("")   recastci(rcap) ciopts(lcolor(navy) lwidth(thick) mcolor(navy) msymbol(i) msize(tiny)) ylabel( 1 "Focus - Community" 2 "Focus - Business" 3 "Focus - Leader" 4 "Age - 59"  5 "Age - 49" 6 "Age - 39"  7 "Education - Doctor" 8 "Education - Masters" 9 "Education - Bachelors" 10 "Non-Party Member" 11 "In Family Network" 12 "Woman", labsize(vsmall))  xtitle("AMCE on Vote Choice", size(vsmall) margin(medium)) xlabel(-.25(.05).25)  ytitle("") title("Honesty Treatment")



reg vote  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan i.female  if   client_group==3, cluster(id)
outreg2 using main_results_11_11, e(all)
margins, dydx(  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan  i.female )
marginsplot,  horizontal plotopts(connect(none)) xline(0, lpattern(dash) lwidth(thick) lcolor(maroon)) title("")   recastci(rcap) ciopts(lcolor(navy) lwidth(thick) mcolor(navy) msymbol(i) msize(tiny)) ylabel( 1 "Focus - Community" 2 "Focus - Business" 3 "Focus - Leader" 4 "Age - 59"  5 "Age - 49" 6 "Age - 39"  7 "Education - Doctor" 8 "Education - Masters" 9 "Education - Bachelors" 10 "Non-Party Member" 11 "In Family Network" 12 "Woman", labsize(vsmall))  xtitle("AMCE on Vote Choice", size(vsmall) margin(medium)) xlabel(-.25(.05).25)  ytitle("") title("Clientelism Treatment")


gen client_group2 =.
replace client_group2=1 if client_group==1
replace client_group2=2 if client_group==3


reg vote  i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan i.female##i.client_group2   , cluster(id)
outreg2 using main_results_11_11, e(all) excel


reg vote i.female##i.client_group2 , cluster(id)
margins client_group2#female
mplotoffset, offset(0.15) plot1opts(connect(no) msize(medlarge) msymbol(triangle) mcolor(gs4)) plot2opts(connect(no) msize(medlarge)  mcolor(gs8))  xlabel(.6 " " 1 "Control" 2  "Clientelism Treatment" 2.4 " ", notick labsize(small)) xtitle(" ") title("") legend(pos(6) row(1)) ci1opts(lcolor(gs4) lwidth(medthick) msize(large)) ci2opts(lcolor(gs8) lwidth(medthick) msize(large))
graph save g3_11_11, replace


**** Het Effects
reg vote i.female##i.income_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group2==1, cluster(id)

reg vote i.female##i.income_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group2==2, cluster(id)

reg vote i.female##c.income_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group2==2, cluster(id)

reg vote i.female##c.income_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group2==1, cluster(id)

reg vote i.female##i.education_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group2==1, cluster(id)

reg vote i.female##i.education_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan  if client_group2==2, cluster(id)

reg vote i.female##c.education_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if  client_group==2, cluster(id)

reg vote i.female##c.education_pc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group==1, cluster(id)


reg vote i.female##i.khuvuc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group==3, cluster(id)

reg vote i.female##i.khuvuc i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if  client_group==1, cluster(id)

reg vote i.female##i.kinh i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if  client_group==3, cluster(id)

reg vote i.female##i.kinh i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if  client_group==1, cluster(id)

reg vote i.female##i.woman i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if  client_group==3, cluster(id)

reg vote i.female##i.woman i.ben_community i.ben_biz i.ben_leaders i.age59 i.age49  i.age39 i.doctorate i.masters i.bachelors   i.non_party  i.inclan if client_group==1, cluster(id)
